package Calculation.L2;

import java.util.ArrayList;
import java.util.List;


//算法设计题： 10
public class L2N2 {
    public static List<Integer> getExitOrder(int n) {
        List<Integer> result = new ArrayList<>();
        List<Integer> current = new ArrayList<>();
        for (int i = 1; i <= n; i++) {
            current.add(i);
        }
        while (!current.isEmpty()) {
            List<Integer> temp = new ArrayList<>();
            List<Integer> next = new ArrayList<>();
            for (int i = 0; i < current.size(); i++) {
                if (i % 2 == 0) {
                    temp.add(current.get(i));
                } else {
                    next.add(current.get(i));
                }
            }
            result.addAll(temp);
            current = next;
        }
        return result;
    }

    public static void main(String[] args) {
        int n = 5;
        List<Integer> order = getExitOrder(n);
        System.out.println(order); // 输出 [1, 3, 5, 2, 4]
    }
}